<template>
  <div class="app-container">
    <el-form ref="diagnosis" :rules="rules" :model="diagnosis" label-width="150px">
      <el-form-item label="诊断编号" prop="code">
        <el-input v-model="diagnosis.code" />
      </el-form-item>
      <el-form-item label="诊断名称" prop="name">
        <el-input v-model="diagnosis.name" />
      </el-form-item>
      <el-form-item label="标准编码" prop="standardCode">
        <el-input v-model="diagnosis.standardCode" />
      </el-form-item>
      <el-form-item label="性别限制" prop="genderRestrict">
        <el-radio-group v-model="diagnosis.genderRestrict">
          <el-radio :label="0">不限</el-radio>
          <el-radio :label="1">限男性</el-radio>
          <el-radio :label="2">限女性</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div class="op-container">
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleCreate">保存</el-button>
    </div>
  </div>
</template>

<script>
import { createDiagnosis } from "@/api/diagnosis"
import { MessageBox } from "element-ui"

export default {
  name: "DiagnosisCreate",
  data() {
    return {
      diagnosis: {
        code: '',
        name: '',
        standardCode: '',
        genderRestrict: 0
      },
      rules: {
        name: [{ required: true, message: '诊断名称不能为空', trigger: 'blur' }]
      },
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {},
    handleCancel() {
      this.$router.push({ path: '/diagnosis/list' })
    },
    handleCreate() {
      createDiagnosis(this.diagnosis).then(response => {
        this.$notify.success({
          title: '成功',
          message: '创建成功'
        })
        this.$router.push({ path: '/diagnosis/list' })
      }).catch(response => {
        MessageBox.alert('业务错误：' + response.data.errmsg, '警告', {
          confirmButtonText: '确定',
          type: 'error'
        })
      })
    }
  }
}
</script>

<style scoped>
.op-container {
  display: flex;
  justify-content: center;
}
</style>
